import dearpygui.dearpygui as dpg

###################################
#Constant
###################################
font_path = "SourceHanSans-CN-Bold.ttf" 
# count = 0

###################################
#Init Dear PyGui
###################################
dpg.create_context()
dpg.setup_dearpygui()
dpg.create_viewport(title='FPGA_simulation', width=1200, height=800)

###################################
#Main Workspace
###################################
with dpg.font_registry():
    with dpg.font(font_path, 14) as default_font:
        dpg.add_font_range_hint(dpg.mvFontRangeHint_Chinese_Simplified_Common)

with dpg.window(label="Main Window", tag="Main Window"):
    with dpg.menu_bar():
        with dpg.menu(label="Themes"):
            dpg.add_menu_item(label="Dark")
            dpg.add_menu_item(label="Light")
        with dpg.menu(label="Tools"):
            dpg.add_menu_item(label="Show Logger")
            dpg.add_menu_item(label="Show About")
        with dpg.menu(label="Oddities"):
            dpg.add_button(label="A Button")
            dpg.add_simple_plot(label="Menu plot", default_value=(0.3, 0.9, 2.5, 8.9), height=80)
    with dpg.group(horizontal=True):
        with dpg.group(horizontal=False, width=100):
            dpg.bind_font(default_font)
            dpg.add_text("Hello, world")
            dpg.add_button(tag="Btn2", label="Button 2", height=50)
            with dpg.group(horizontal=True):
                dpg.add_button(label="Button 3")
                dpg.add_button(label="Button 4")
        with dpg.group(horizontal=False):
            dpg.add_text("Hello, world")
            dpg.add_text("把鼠标放我上面!", tag="text item")
            dpg.add_checkbox(label="Radio Button1", default_value=True)
            # with dpg.node_editor(label="Node Editor"):
            #     with dpg.node(label="Node 1"):
            #         dpg.add_node_attribute(label="Attribute 1")
            #     with dpg.node(label="Node 2"):
            #         dpg.add_node_attribute(label="Attribute 3")
            dpg.add_draw_layer
            with dpg.drawlist(width=500, height=500):
                dpg.draw_rectangle((0, 0), (500, 500), color=(255, 0, 0, 255), thickness=1)

def change_text(sender, app_data):
    if dpg.is_item_hovered("text item"):   #component listening
        dpg.set_value("text item", f"爬开!!")
    else:
        dpg.set_value("text item", f"把鼠标放我上面!")

def update_per_frame(): #update per frame
    # global count
    # count+=1
    # print(count)
    pass

with dpg.handler_registry():
    dpg.add_mouse_move_handler(callback=change_text)   #鼠标移动侦听

###################################
#Development Tool
###################################

# dpg.show_documentation() #--help
# dpg.show_style_editor() #--style
# dpg.show_font_manager() #--font
# dpg.show_debug() #--help --debug useless
# dpg.show_about() #--about
# dpg.show_metrics() #--metrics --debug
# dpg.show_item_registry() #--registry --Element Browser


###################################
#Run the GUI
###################################
dpg.set_primary_window("Main Window", True)
dpg.set_viewport_large_icon("favicon/favicon.ico")
dpg.show_viewport()

while dpg.is_dearpygui_running(): 
    update_per_frame()
    dpg.render_dearpygui_frame() #update per frame

dpg.start_dearpygui()
dpg.destroy_context()
